@(modelForView: model.forview.TypeCreateModelForView)
@main(modelForView.mainModelForView) {

<!-- CONTENT -->
<div class="offset3 span6">
	<div class="well pagination-centered">
		<h3>Форма типа данных</h3>
	</div>
</div>
<div class="offset3 span6">
	<!-- TYPE CREATE FORM -->
	<form class="form-horizontal " method="POST">
		<!-- Основные данные -->
		<div class="well">
			<div class="pagination-centered">
				<h4>Основные данные</h4>
			</div>
			<div class="control-group">
				<label class="control-label">Заголовок</label>
				<div class="controls">
					<input name="@modelForView.titleName" type="text" value="@modelForView.title" placeholder="Описание">
				</div>
			</div>
			
			<!-- DESCRIPTION -->
			<div class="control-group">
				<label class="control-label">Описание</label>
				<div class="controls">
					<textarea name="@modelForView.descriptionName" value="" placeholder="@modelForView.descriptionLabel">
						@modelForView.description
					</textarea>
				</div>
			</div>	
			
		</div>
		
		
		<!-- HIDDEN VALUES -->
		<input name="@modelForView.type_nameName" type="hidden" value="@modelForView.type_name">
		<input name="@modelForView.type_titleName" type="hidden" value="@modelForView.type_title">
		<div class="well">
			<div class="pagination-centered">
				<h4>Примитивные типы данных:</h4>
			</div>
			
			<!-- ADDITIONAL FIELDS -->
			<div class="control-group">
				<table style="width:100%">
					<tr>
						<td><input type="radio" name="type_field" value="b"> Файл <Br></td>
						<td><input type="radio" name="type_field" value="p"> Ссылка <Br></td>
					</tr>
					<tr>
						<td><input type="radio" name="type_field" value="s"> Строка <Br></td>
						<td><input type="radio" name="type_field" value="f"> Число <Br></td>
						<td><input type="radio" name="type_field" value="u"> Пользователь <Br></td>
					</tr>
				</table>
	   				
	   			<button id="id_button_add_field" type="button" class="btn" onclick="return false;">Добавить</button>
			</div>
		</div>
		
		<div id="id_addition_fields">
		
			
			
		</div>
		<!-- BUTTONS -->
		<div class="form-actions">
			<button id="id_button_submit" type="submit" class="btn btn-primary">Создать</button>
			<!--<button type="reset" class="btn">@modelForView.cancelButton</button>-->
		</div>
	</form>
</div>
<!-- SCRIPT FOR TYPE CREATE -->
<script>
//Sorry for this shit
function fillHiddeField()
{
	var allTitle = $('#id_addition_fields div div div input:text');
	var allHidden = $('#id_addition_fields div input:hidden');
	var titles="", hiddens="";
	for(var i=0; i<allHidden.size();i++)
	{
		titles = titles + ($(allTitle.get(i)).val()).replace(";","") + ';';
		hiddens = hiddens + ($(allHidden.get(i)).val()) + ';';
	}
	
	$('input[name=@modelForView.type_nameName]').val(hiddens);
	$('input[name=@modelForView.type_titleName]').val(titles);
		
}
function deleteField(fieldId)
{
	var idJQ = '#'+fieldId;
	$(idJQ).remove();
	fillHiddeField()
}
function addField(fieldType)
{
	var fieldId = 'fieldId_'+(Math.random());
	fieldId = fieldId.replace(".","");
	$('#id_addition_fields').append(
		//'<div id="'+fieldId+'"><input type="text" value="" ><input type="hidden" value="'+fieldType+'">'+
		//'<a href="#" onclick="deleteField(\''+fieldId+'\');return fasle;">Удалить</a>'+
		//'</div>'
		
		'<div id="'+fieldId+'" class="well">'
			+'<input type="hidden" value="'+fieldType+'">'
			+'<div class="pagination-centered"><h4>'+getTitleOfType(fieldType)+'</h4></div>'
			+'<div class="control-group">'
				+'<label class="control-label">Заголовок</label>'
				+'<div class="controls">'
					+'<input type="text" placeholder="Описание">'
				+'</div>'
			+'</div>'
			+'<a href="#" class="btn" onclick="deleteField(\''+fieldId+'\');return fasle;">Удалить</a>'
		+'</div>'		
	);
	fillHiddeField();
}
function getTitleOfType(fieldType)
{
	if(fieldType == 'p') return "Ссылка";
	if(fieldType == 's') return "Строка";
	if(fieldType == 'f') return "Число";
	if(fieldType == 'b') return "Файл";
	if(fieldType == 'u') return "Пользователь";
}
$(document).ready(function () {
   $('#id_button_submit').click(function(){	   
	   fillHiddeField();	   
	});
   $('#id_button_add_field').click(function(){	   
	   addField($('input:radio[name=type_field]:checked').val());	   
	});
});
</script>
}
